package com.open.capacity.exam.service.impl;

import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.ExamQuestionsType;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.exam.dao.QuestionTypeDao;
import com.open.capacity.exam.service.QuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class QuestionTypeServiceImpl implements QuestionTypeService {
    @Autowired
    private QuestionTypeDao typeDao;

    /**
     * 查询考题类型
     * @param param
     * @return
     */
    @Override
    public PageResult<ExamQuestionsType> findAll(Map<String,Object> param) throws ServiceException {
        PageUtil.pageParamConver(param,false);
        List<ExamQuestionsType> list = typeDao.selectAll(param);
        int count = typeDao.selectAllCount(param);
        return PageResult.<ExamQuestionsType>builder().data(list).count((long)count).build();
    }

    /**
     * 新增考题类型
     * @param type
     * @return
     */
    @Override
    public Result addType(ExamQuestionsType type) {
        int insert=typeDao.insert(type);
        return insert>0?Result.succeed("添加成功"):Result.failed("操作失败");
    }

    /**
     * 考题类型修改：类型名和使用状态
     * @param type
     * @return
     */
    @Override
    public Result editType(ExamQuestionsType type) {
        Integer update=typeDao.update(type);
        return update>0?Result.succeed("修改成功"):Result.failed("操作失败");
    }
}
